package com.dormitoryAdministratorSystem.util;

import com.dormitoryAdministratorSystem.dao.clazz.impl.ClassDaoImpl;
import com.dormitoryAdministratorSystem.dao.room.impl.RoomDaoImpl;
import com.dormitoryAdministratorSystem.dao.student.impl.StudentDaoImpl;
import com.dormitoryAdministratorSystem.entity.clazz.ClassBean;
import com.dormitoryAdministratorSystem.entity.maintain.Maintain;
import com.dormitoryAdministratorSystem.entity.room.RoomBean;
import com.dormitoryAdministratorSystem.entity.student.StudentBean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BeansUtil {
    private static StudentDaoImpl sdi = new StudentDaoImpl();

    private static ClassDaoImpl cdi = new ClassDaoImpl();

    private static RoomDaoImpl rdi = new RoomDaoImpl();

    private static Map<String, ClassBean> cMap;

    private static Map<String, RoomBean> rMap;

    private BeansUtil(){}

    public static List<StudentBean> getStudents(int rId){
        return sdi.getStudentByRoomId(rId);
    }

    public static RoomBean getRoom(int rid){
        if(rid == 0){
            RoomBean r = new RoomBean();
            r.setRId(0);
            r.setAddress("暂无房间");
            return  r;
        }
        return rdi.getRoomInfo(rid);
    }

    public static ClassBean getClass( int cId) {
        return cdi.getClassBean(cId);
    }

    public static Maintain getMaintain(int mId){
        return null;
    }

    public static Map<String, ClassBean> getcMap(){
        cMap = new HashMap<>();
        List<ClassBean> cList = cdi.getAllClasses();
        for (ClassBean classBean : cList) {
            cMap.put(classBean.getCName(), classBean);
        }
        return cMap;
    }

    public static Map<String, RoomBean> getrMap(){
        rMap = new HashMap<>();
        List<RoomBean> rList = rdi.getCanLiveRoom();
        for (RoomBean roomBean : rList) {
            rMap.put(roomBean.getAddress(), roomBean);
        }
        return rMap;
    }
}
